home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Form & Validation / check-all.izs < prev    next >
Text File  |  2005-08-29  |  2KB  |  60 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Check all check/radio buttons
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>A good addition to your forms if they contain a multitude of check/radio buttons is a "check/uncheck all" feature. This script does just that for any group of checkboxes and radio buttons.
  7. <!/DESCRIPTION> 
  8.  
  9. <!CATEGORY>form and form validation<!/CATEGORY>
  10.  
  11. <!SCRIPT>
  12. <!-- START OF SCRIPT -->
  13. <script>  
  14.  
  15. function checkall(formname,checkname,thestate){
  16. var el_collection=eval("document.forms."+formname+"."+checkname)
  17. for (c=0;c<el_collection.length;c++)
  18. el_collection[c].checked=thestate
  19. }
  20.  
  21. </script>
  22. <form name="test">
  23. <input type="checkbox" name="v1"> Peter<br>
  24. <input type="checkbox" name="v1"> Jane<br>
  25. <input type="checkbox" name="v1"> George<br>
  26. </form>
  27.  
  28. <!-- checkall(name of form, common name of checkbox group, true or false)-->
  29.  
  30. <a href="javascript:checkall('test','v1',true)">Check All</a><br>
  31. <a href="javascript:checkall('test','v1',false)">Uncheck All</a>
  32. <!-- END OF SCRIPT -->
  33. <!/SCRIPT>
  34.  
  35. <!PREVIEW>
  36. <!-- START OF SCRIPT -->
  37.  
  38. <script>  
  39.  
  40. function checkall(formname,checkname,thestate){
  41. var el_collection=eval("document.forms."+formname+"."+checkname)
  42. for (c=0;c<el_collection.length;c++)
  43. el_collection[c].checked=thestate
  44. }
  45.  
  46. </script>
  47. <form name="test">
  48. <input type="checkbox" name="v1"> Peter<br>
  49. <input type="checkbox" name="v1"> Jane<br>
  50. <input type="checkbox" name="v1"> George<br>
  51. </form>
  52.  
  53. <!-- checkall(name of form, common name of checkbox group, true or false)-->
  54.  
  55. <a href="javascript:checkall('test','v1',true)">Check All</a><br>
  56. <a href="javascript:checkall('test','v1',false)">Uncheck All</a>
  57. <!-- END OF SCRIPT -->
  58. <!/PREVIEW>
  59.  
  60. <!RELATED>NONE<!/RELATED>